package com.example.demo.excel.listener;

import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.V;
import com.diboot.file.excel.listener.FixedHeadExcelListener;

import com.example.demo.entity.OrderSku;
import com.example.demo.excel.model.OrderSkuImportModel;
import com.example.demo.service.OrderSkuService;


import java.util.List;
import java.util.Map;

/**
* 项目文件 导入Listener定义
* @author MyName
* @version 1.0
* @date 2023-09-13
* Copyright © MyCompany
*/
public class OrderSkuImportListener extends FixedHeadExcelListener<OrderSkuImportModel> {

    /**
    * 自定义校验规则
    * @param dataModelList    待保存的数据
    * @param requestParams  请求参数
    */
    @Override
    protected void additionalValidate(List<OrderSkuImportModel> dataModelList, Map<String, Object> requestParams) {
        // 附加校验
    }

    /**
    * 保存数据
    * @param dataModelList 待保存的数据
    * @param requestParams 请求参数
    */
    @Override
    protected void saveData(List<OrderSkuImportModel> dataModelList, Map<String, Object> requestParams) {
        if (V.isEmpty(dataModelList)) {
            return;
        }
        List<OrderSku> entityList = BeanUtils.convertList(dataModelList, OrderSku.class);
        ContextHelper.getBean(OrderSkuService.class).createEntities(entityList);
    }
}
